package com.ad.pet.app;


import com.ad.pet.common.structure.mvp.BaseView;

/**
 * Created by z on.
 * Des:
 * Date: 2017/5/18
 */

public abstract class AppUseCaseCallback<R> implements UseCase.UseCaseCallback<R> {
    BaseView mView;
    boolean progress;

    public AppUseCaseCallback(BaseView baseView) {
        this(baseView, true);
    }

    public AppUseCaseCallback(BaseView view, boolean progress) {
        mView = view;
        this.progress = progress;
    }

    @Override
    public void onStart() {
        if (progress) if (mView != null) mView.showLoading();

    }

    @Override
    public void onSuccess(R response) {
        if (mView != null)  onNext(response);
    }

    @Override
    public void onError(String errorMsg) {
        if (progress) if (mView != null) mView.hideLoading();if (mView != null) mView.error(errorMsg);
    }

    @Override
    public void onComplete() {
        if (progress) if (mView != null) mView.hideLoading();
    }

    protected abstract void onNext(R response);
}
